// 对于数据请求的封装
// import axios from "axios"
// 第一种方案 通过方法调用 把分散在各个文件的请求封装到一个文件
// function httpForList(){
//     return axios({
//         url: 'https://m.maizuo.com/gateway?cityId=511400&pageNum=1&pageSize=10&type=1&k=349429',
//         headers: {
//           'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16519315511006212053204993"}',
//           'X-Host': 'mall.film-ticket.film.list'
//         }
//     })
// }
// function httpForDetail(){
//     return axios({
//         url: `https://m.maizuo.com/gateway?filmId=${this.$route.params.id}&k=9692906`,
//         headers: {
//           'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"1651821871954839949377537","bc":"110100"}',
//           'X-Host': 'mall.film-ticket.film.info'

//         }
//       })
// }
// export default {
//     httpForList,
//     httpForDetail
// }

// 第二种方案
import axios from "axios"
import { Toast } from 'vant';
const http = axios.create({
	baseURL: 'https://m.maizuo.com',
	timeout: 10000,
	headers: {
			'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.0","e":"16519315511006212053204993"}',
      }
})

// 在发请求之前拦截 -- showLoading
http.interceptors.request.use(function (config) {
	Toast.loading({
		message: '加载中...',
		forbidClick: true,
		duration: 0
	});
	return config
}, function (error) {
	return Promise.reject(error)
})
// 在请求成功后拦截 -- hideLoading
http.interceptors.response.use(function (response) {
	
	Toast.clear()
	return {
		...response
	}
}, function (error) {

	Toast.clear()
	return Promise.reject(error)
})
export default http